package com.cjm.one.common.config.jackson;


import com.cjm.one.common.config.jackson.converter.BaseEnumDeserializer;
import com.cjm.one.common.config.jackson.converter.BaseEnumSerializer;
import com.cjm.one.model.base.BaseEnum;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JacksonConfiguration {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            builder // 序列化枚举
                    .serializerByType(BaseEnum.class, new BaseEnumSerializer())  // 反序列化枚举
                    .deserializerByType(BaseEnum.class, new BaseEnumDeserializer());
            // 把 Long 类型序列化为 String
            builder.serializerByType(Long.class, ToStringSerializer.instance)
                    .serializerByType(long.class, ToStringSerializer.instance);


        };
    }
}
